package com.csust.advanced.pool;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.junit.Test;

import javax.sql.DataSource;
import java.io.InputStream;
import java.sql.Connection;
import java.util.Properties;

public class DruidTest  {
    @Test
     public void test() throws Exception{
        DruidDataSource dds = new DruidDataSource();
        dds.setDriverClassName("com.mysql.jdbc.Driver");
        dds.setUrl("jdbc:mysql://127.0.0.1:3306/atguigu?useUnicode=true&characterEncoding=utf8&useSSL=false");

        dds.setUsername("root");
        dds.setPassword("123456");


        dds.setInitialSize(10);
        dds.setMaxActive(20);


        Connection conn = dds.getConnection();

        System.out.println(conn);

        conn.close();



    }
    @Test
    public void test2() throws Exception{
        Properties props = new Properties();

        InputStream is = DruidTest.class.getClassLoader().getResourceAsStream("db.properties");
        props.load(is);


        DataSource ds = DruidDataSourceFactory.createDataSource(props);
        Connection conn = ds.getConnection();
        System.out.println(conn);

        conn.close();


    }
}
